home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 0850 / wspi_src.zip / WS_PAINT.C < prev    next >
C/C++ Source or Header  |  1994-01-20  |  4KB  |  154 lines

  1. /*************************************************************************
  2.  Windows Sockets Application Support Module
  3.  Written by John A. Junod, 267 Hillwood St., Martinez, GA, 30907 93.10.01
  4.  <junodj@css583.gordon.army.mil>     <zj8549@trotter.usma.edu> 
  5.  
  6.  Released into the public domain with no restrictions other than to give
  7.  me some of the credit if you use this code in other applications. 
  8. *************************************************************************/
  9. /*
  10.   MODULE: WS_PAINT.C  (main window (debug) display routines)
  11. */
  12.  
  13. #include "ws_glob.h"
  14. #include "ws_ping.h"
  15.  
  16. #include <stdarg.h>
  17.  
  18. int nLineHeight=5;
  19. int nScreenRows=10;
  20.  
  21. // extern HWND hWndDbg;
  22.  
  23. void ReleaseDisplayMem()
  24. {
  25.   int nIndex;
  26.   for(nIndex=0;nIndex<ptrhGMem;nIndex++)
  27.     GlobalFree(hGMem[nIndex]);
  28.   ptrhGMem=0;
  29. }
  30.  
  31. void DoAddLine(LPSTR szString)
  32. {
  33.   GLOBALHANDLE hGlobalMemory;
  34.   LPSTR lpGlobalMemory;
  35.   int nIndex;
  36.   RECT rect;
  37.  
  38.   if(!(bVerbose) && szString[0]=='[')
  39.     return;
  40.  
  41.   // added in some error checking to try to eliminate GPFs
  42.   if(szString) {
  43.     nIndex=_fstrlen(szString);
  44.     if(nIndex>0 && (hGlobalMemory=GlobalAlloc(GMEM_MOVEABLE,nIndex))!=NULL) {
  45.       if((lpGlobalMemory=GlobalLock(hGlobalMemory))!=NULL) {
  46.         lstrcpy(lpGlobalMemory,szString);
  47.         GlobalUnlock(hGlobalMemory);
  48.         if(ptrhGMem<90) {
  49.           hGMem[ptrhGMem++]=hGlobalMemory;
  50.         } else {
  51.           if(GlobalFree(hGMem[0])==NULL) {
  52.             for(nIndex=0;nIndex<90;nIndex++)
  53.               hGMem[nIndex]=hGMem[nIndex+1];
  54.             hGMem[ptrhGMem-1]=hGlobalMemory;
  55.           }
  56.         }
  57.       }
  58.     }
  59.   }
  60.   GetClientRect(hWndMain,&rect);
  61.   rect.top=min(0,(ptrhGMem-sVPos-1))*nLineHeight;
  62.  
  63.   if(ptrhGMem > (sVPos+nScreenRows))
  64.     PostMessage(hWndMain,WM_VSCROLL,SB_LINEDOWN,0L);
  65.   else
  66.     InvalidateRect(hWndMain,&rect,TRUE);
  67.  
  68.   UpdateWindow(hWndMain);
  69. }
  70.  
  71. void DoPrintf(char *szFormat,...)
  72. {
  73.    va_list vaArgs;
  74.    static char szBuf[256];
  75.  
  76.    va_start(vaArgs,szFormat);
  77.    if(vsprintf(szBuf,szFormat,vaArgs)!=EOF)
  78.      DoAddLine(szBuf);
  79.    va_end(vaArgs);
  80. }
  81.  
  82. void DoPaint(HWND hWnd)
  83. {
  84.   HDC         hDC;   // handle for the display device
  85.   PAINTSTRUCT ps;    // holds PAINT information
  86.   int         nRc;
  87.   int         nIndex;
  88.   LPSTR       lpMem;
  89.  
  90.   RECT rRect;
  91.   TEXTMETRIC tm;
  92.  
  93.   memset(&ps, 0x00, sizeof(PAINTSTRUCT));
  94.   hDC = BeginPaint(hWnd, &ps);
  95.   // Included as the background is not a pure color
  96.   SetBkMode(hDC, TRANSPARENT);
  97.   GetTextMetrics(hDC,&tm);
  98.   nLineHeight=tm.tmHeight+tm.tmExternalLeading;
  99.   GetClientRect(hWnd,&rRect);
  100.   nScreenRows=rRect.bottom/nLineHeight;
  101.   if(nScreenRows >= ptrhGMem)
  102.       ShowScrollBar(hWnd,SB_VERT,FALSE);
  103.   else
  104.       ShowScrollBar(hWnd,SB_VERT,TRUE);
  105.   for(nIndex=0;(nIndex+sVPos)<ptrhGMem;nIndex++) {
  106.     lpMem=GlobalLock(hGMem[nIndex+sVPos]);
  107.     if(lpMem!=NULL) {
  108.       TextOut(hDC,20,nIndex*nLineHeight,lpMem,lstrlen(lpMem));
  109.       GlobalUnlock(hGMem[nIndex+sVPos]);
  110.     }
  111.   }
  112.   // Inform Windows painting is complete
  113.   EndPaint(hWnd, &ps);
  114. }
  115.  
  116. int GetLocalInfo()
  117. {
  118.   int nRc;
  119.   struct hostent *hostptr;
  120.   char *ptr;
  121.   struct in_addr *iptr;
  122.  
  123.   DoPrintf("Description: %s",(LPSTR)WSAData.szDescription);
  124.   DoPrintf("System Status: %s", (LPSTR)WSAData.szSystemStatus);
  125. /*
  126.   DoPrintf("Version: %04x %04x %d %d",
  127.         (WORD)WSAData.wVersion,(WORD)WSAData.wHighVersion,
  128.         (int)WSAData.iMaxSockets,(int)WSAData.iMaxUdpDg);
  129. */
  130.   if((nRc=gethostname((LPSTR)szString,
  131.              MAXHOSTNAMELEN))==SOCKET_ERROR)
  132.     ReturnWSError(WSAGetLastError(),&szMsgBuf[strlen(szMsgBuf)]);
  133.   else
  134.     DoPrintf("Local Hostname: %s",szString);
  135.  
  136.   if(!nRc)
  137.   {
  138.     if((hostptr=gethostbyname(szString))==NULL) {
  139.       DoPrintf("gethostbyname failure.");
  140.       ReportWSError(WSAGetLastError());
  141.     } else {
  142. /*
  143.       DoPrintf("Official Name: %s",hostptr->h_name);
  144. */
  145.       while ( (iptr = (struct in_addr *) *(hostptr->h_addr_list)) != NULL) {
  146.         DoPrintf("Local Address: %s",inet_ntoa(*iptr));
  147.         hostptr->h_addr_list++;
  148.       }
  149.     }
  150.   }
  151.   return(TRUE);
  152. }
  153.  
  154.